﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AutoUpdate.Comm;
using Microsoft.Win32;

namespace AutoUpdate
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        private void btn_Open_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.ShowDialog();
            this.txt_FileSource.Text = ofd.FileName; // 源文件路径
            FileInfo fileInfo = new FileInfo(this.txt_FileSource.Text);
            this.txt_FileSize.Text = fileInfo.Length.ToString(); // 文件大小
            this.txt_FileDate.Text = fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); // 最后一次修改日期
            this.txt_FileSizeUnit.Text = CommHelper.ConverBytes(fileInfo.Length); // 带单位的文件大小

            // 从注册表里面获取文件类型
            RegistryKey key;
            key = Registry.ClassesRoot;
            RegistryKey extensionReg = key.OpenSubKey(fileInfo.Extension);
            if (extensionReg != null)
            {
                RegistryKey fileTypeReg = key.OpenSubKey(extensionReg.GetValue("").ToString());
                if(fileTypeReg != null)
                    this.txt_FileType.Text = fileTypeReg.GetValue("").ToString();
            }

            this.txt_Remark.Text = fileInfo.Name; // 文件名称填写到备注字段里面

            Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(this.txt_FileSource.Text);
            if(icon != null)
                this.pic_Icon.Image = icon.ToBitmap();

        }

        private void btn_Version_Click(object sender, EventArgs e)
        {
            FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(this.txt_FileSource.Text);
            this.txt_FileName.Text = versionInfo.FileVersion;
        }

        private void Main_Load(object sender, EventArgs e)
        {

        }

        public void Bind()
        {

        }

        private void tmsi_OpenDataBase_Click(object sender, EventArgs e)
        {

        }
    }
}
